home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sermgrax / frmstart.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-15  |  11.6 KB  |  341 lines

  1. VERSION 5.00
  2. Begin VB.Form frmStartup 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Service"
  5.    ClientHeight    =   4650
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4185
  9.    Icon            =   "frmStartup.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4650
  14.    ScaleWidth      =   4185
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   1  'CenterOwner
  17.    Begin VB.Frame Frame2 
  18.       Caption         =   "Log On As:"
  19.       Height          =   2535
  20.       Left            =   120
  21.       TabIndex        =   6
  22.       Top             =   2040
  23.       Width           =   3975
  24.       Begin VB.TextBox txtConfirmPassword 
  25.          Height          =   285
  26.          IMEMode         =   3  'DISABLE
  27.          Left            =   1560
  28.          PasswordChar    =   "*"
  29.          TabIndex        =   14
  30.          Top             =   2040
  31.          Width           =   2175
  32.       End
  33.       Begin VB.TextBox txtPassword 
  34.          Height          =   285
  35.          IMEMode         =   3  'DISABLE
  36.          Left            =   1560
  37.          PasswordChar    =   "*"
  38.          TabIndex        =   12
  39.          Top             =   1560
  40.          Width           =   2175
  41.       End
  42.       Begin VB.TextBox txtAccountName 
  43.          Height          =   285
  44.          Left            =   1560
  45.          TabIndex        =   10
  46.          Top             =   1080
  47.          Width           =   2175
  48.       End
  49.       Begin VB.CheckBox chkInteract 
  50.          Caption         =   "A&llow Service to Interact with Desktop"
  51.          Height          =   195
  52.          Left            =   480
  53.          TabIndex        =   8
  54.          Top             =   720
  55.          Width           =   3135
  56.       End
  57.       Begin VB.OptionButton optThisAccount 
  58.          Caption         =   "&This Account:"
  59.          Height          =   255
  60.          Left            =   120
  61.          TabIndex        =   9
  62.          Top             =   1080
  63.          Width           =   1455
  64.       End
  65.       Begin VB.OptionButton optSystemAccount 
  66.          Caption         =   "&System Account"
  67.          Height          =   255
  68.          Left            =   120
  69.          TabIndex        =   7
  70.          Top             =   360
  71.          Width           =   1455
  72.       End
  73.       Begin VB.Label lblPassword2 
  74.          Caption         =   "Password:"
  75.          Height          =   255
  76.          Left            =   480
  77.          TabIndex        =   13
  78.          Top             =   2160
  79.          Width           =   975
  80.       End
  81.       Begin VB.Label lblConfirm 
  82.          Caption         =   "&Confirm"
  83.          Height          =   255
  84.          Left            =   480
  85.          TabIndex        =   17
  86.          Top             =   1920
  87.          Width           =   855
  88.       End
  89.       Begin VB.Label lblPassword 
  90.          Caption         =   "&Password:"
  91.          Height          =   255
  92.          Left            =   480
  93.          TabIndex        =   11
  94.          Top             =   1560
  95.          Width           =   855
  96.       End
  97.    End
  98.    Begin VB.CommandButton cmdCancel 
  99.       Cancel          =   -1  'True
  100.       Caption         =   "Cancel"
  101.       Height          =   375
  102.       Left            =   3000
  103.       TabIndex        =   16
  104.       Top             =   1080
  105.       Width           =   1095
  106.    End
  107.    Begin VB.CommandButton cmdOK 
  108.       Caption         =   "OK"
  109.       Default         =   -1  'True
  110.       Height          =   375
  111.       Left            =   3000
  112.       TabIndex        =   15
  113.       Top             =   600
  114.       Width           =   1095
  115.    End
  116.    Begin VB.Frame Frame1 
  117.       Caption         =   "Startup Type"
  118.       Height          =   1335
  119.       Left            =   120
  120.       TabIndex        =   2
  121.       Top             =   480
  122.       Width           =   2655
  123.       Begin VB.OptionButton optDisabled 
  124.          Caption         =   "&Disabled"
  125.          Height          =   255
  126.          Left            =   120
  127.          TabIndex        =   5
  128.          Top             =   960
  129.          Width           =   1695
  130.       End
  131.       Begin VB.OptionButton optManual 
  132.          Caption         =   "&Manual"
  133.          Height          =   255
  134.          Left            =   120
  135.          TabIndex        =   4
  136.          Top             =   600
  137.          Width           =   1695
  138.       End
  139.       Begin VB.OptionButton optAutomatic 
  140.          Caption         =   "&Automatic"
  141.          Height          =   255
  142.          Left            =   120
  143.          TabIndex        =   3
  144.          Top             =   240
  145.          Width           =   1695
  146.       End
  147.    End
  148.    Begin VB.Label lblServiceName 
  149.       Caption         =   "Service Name"
  150.       Height          =   255
  151.       Left            =   1080
  152.       TabIndex        =   1
  153.       Top             =   120
  154.       Width           =   3495
  155.    End
  156.    Begin VB.Label Label1 
  157.       Caption         =   "Service:"
  158.       Height          =   255
  159.       Left            =   120
  160.       TabIndex        =   0
  161.       Top             =   120
  162.       Width           =   735
  163.    End
  164. Attribute VB_Name = "frmStartup"
  165. Attribute VB_GlobalNameSpace = False
  166. Attribute VB_Creatable = False
  167. Attribute VB_PredeclaredId = True
  168. Attribute VB_Exposed = False
  169. '****************************************************************************************************
  170. '   Copyright (c) Key Technology Pty Ltd 1999, All Rights Reserved.
  171. '   Web site: http://www.keytech.com.au  Email: info@keytech.com.au
  172. '****************************************************************************************************
  173. Option Explicit
  174. Private mServiceName As String
  175. Private mConfigurationChanged As Boolean
  176. Private mAllowServiceToInteract As Boolean
  177. Private mAccountName As String
  178. Private mPassword As String
  179. Private mPasswordChanged As Boolean
  180. Private Sub optSystemAccount_Click()
  181.     chkInteract.Enabled = True
  182.     If mAllowServiceToInteract Then chkInteract = vbChecked
  183.     mAccountName = txtAccountName
  184.     txtAccountName.Enabled = False
  185.     lblPassword.Enabled = False
  186.     lblConfirm.Enabled = False
  187.     lblPassword2.Enabled = False
  188.     txtPassword.Enabled = False
  189.     txtConfirmPassword.Enabled = False
  190.     txtAccountName = ""
  191.     txtPassword = ""
  192.     txtConfirmPassword = ""
  193. End Sub
  194. Private Sub optThisAccount_Click()
  195.     mAllowServiceToInteract = (chkInteract = vbChecked)
  196.     chkInteract.Enabled = False
  197.     chkInteract = vbUnchecked
  198.     txtAccountName.Enabled = True
  199.     txtAccountName = mAccountName
  200.     lblPassword.Enabled = True
  201.     lblConfirm.Enabled = True
  202.     lblPassword2.Enabled = True
  203.     txtPassword.Enabled = True
  204.     txtConfirmPassword.Enabled = True
  205.     txtPassword = Space(14)
  206.     txtConfirmPassword = txtPassword
  207.     mPasswordChanged = False
  208. End Sub
  209. Private Sub txtPassword_Change()
  210.     mPasswordChanged = True
  211. End Sub
  212. Private Sub txtConfirmPassword_Change()
  213.     mPasswordChanged = True
  214. End Sub
  215. Private Sub cmdCancel_Click()
  216.     Unload Me
  217. End Sub
  218. Private Sub cmdOK_Click()
  219.     On Error GoTo ErrorHandler
  220.     ' If a password has been specified make sure it's been confirmed
  221.     If optThisAccount And mPasswordChanged Then
  222.         If Len(txtPassword) <> 0 Or Len(txtConfirmPassword) <> 0 Then
  223.             If txtPassword <> txtConfirmPassword Then
  224.                 MsgBox "The passwords mismatch. Please re-enter.", vbExclamation
  225.                 
  226.                 txtPassword = ""
  227.                 txtConfirmPassword = ""
  228.                 txtPassword.SetFocus
  229.                 
  230.                 Exit Sub
  231.             End If
  232.         End If
  233.     End If
  234.     ' Open the service manager
  235.     Dim ServiceManager As New ServiceManager
  236.     ServiceManager.ComputerName = frmMain.ComputerName
  237.     ServiceManager.AccessMode = WriteAccess
  238.     ' Get the configuration object for the selected service
  239.     Dim ServiceName As String
  240.     Dim ServiceConfiguration As ServiceConfiguration
  241.     ServiceName = frmMain.SelectedServiceName
  242.     Set ServiceConfiguration = ServiceManager.Configuration(ServiceName)
  243.     ' Update the service type - if an interactive process set to use the
  244.     ' localsystem account otherwise the type cannot be changed
  245.     Dim ServiceType As ServiceType
  246.     ServiceType = ServiceConfiguration.ServiceType
  247.     ServiceType = ServiceType And Not InteractiveProcess
  248.     If optSystemAccount And chkInteract = vbChecked Then
  249.         ServiceType = ServiceType Or InteractiveProcess
  250.     End If
  251.     If ServiceType And InteractiveProcess Then
  252.         ServiceConfiguration.AccountName = "LocalSystem"
  253.     End If
  254.     ServiceConfiguration.ServiceType = ServiceType
  255.     ' Update the start type
  256.     Dim StartType As StartType
  257.     If optAutomatic Then StartType = AutoStart
  258.     If optManual Then StartType = DemandStart
  259.     If optDisabled Then StartType = Disabled
  260.     ServiceConfiguration.StartType = StartType
  261.     ' Update the log on account
  262.     Dim AccountName As String
  263.     If optSystemAccount Then
  264.         AccountName = "LocalSystem"
  265.     Else
  266.         AccountName = txtAccountName
  267.     End If
  268.     If AccountName <> "LocalSystem" Then
  269.         If InStr(1, AccountName, "\") = 0 Then
  270.             AccountName = ".\" & AccountName
  271.         End If
  272.     End If
  273.     ServiceConfiguration.AccountName = AccountName
  274.     ' Update the log on account and password
  275.     If optThisAccount And mPasswordChanged Then
  276.         ServiceConfiguration.Password = txtPassword
  277.     End If
  278.         
  279.     mConfigurationChanged = True
  280.     Unload Me
  281.     Exit Sub
  282. ErrorHandler:
  283.     MsgBox Err.Description, vbExclamation
  284. End Sub
  285. Private Sub Form_Load()
  286.     On Error GoTo ErrorHandler
  287.     ' Get the configuration object for the selected service
  288.     Dim ServiceName As String
  289.     Dim ServiceManager As New ServiceManager
  290.     Dim ServiceConfiguration As ServiceConfiguration
  291.     ServiceName = frmMain.SelectedServiceName
  292.     ServiceManager.ComputerName = frmMain.ComputerName
  293.     Set ServiceConfiguration = ServiceManager.Configuration(ServiceName)
  294.     ' Display the service display name
  295.     lblServiceName = ServiceConfiguration.DisplayName
  296.     ' Display startup type
  297.     Select Case ServiceConfiguration.StartType
  298.         Case AutoStart
  299.             optAutomatic = True
  300.             
  301.         Case Disabled
  302.             optDisabled = True
  303.             
  304.         Case Else
  305.             optManual = True
  306.     End Select
  307.     ' If a shared process then must be local system account
  308.     If (ServiceConfiguration.ServiceType And Not InteractiveProcess) = Win32ShareProcess Then
  309.         optSystemAccount.Enabled = False
  310.         optThisAccount.Enabled = False
  311.         
  312.         mAccountName = "LocalSystem"
  313.     Else
  314.         mAccountName = ServiceConfiguration.AccountName
  315.     End If
  316.         
  317.     ' Display log on account
  318.     If mAccountName = "LocalSystem" Then
  319.         optSystemAccount = True
  320.         
  321.         If ServiceConfiguration.ServiceType And InteractiveProcess Then
  322.             mAllowServiceToInteract = True
  323.         End If
  324.         
  325.         optSystemAccount_Click
  326.     Else
  327.         optThisAccount = True
  328.         
  329.         optThisAccount_Click
  330.     End If
  331.     Exit Sub
  332. ErrorHandler:
  333.     MsgBox Err.Description, vbExclamation
  334. End Sub
  335. Public Property Let ServiceName(ByVal NewValue As String)
  336.     mServiceName = NewValue
  337. End Property
  338. Public Property Get ConfigurationChanged() As Boolean
  339.     ConfigurationChanged = mConfigurationChanged
  340. End Property
  341.